package com.ocean.web.controller.product;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ocean.common.annotation.Log;
import com.ocean.common.enums.BusinessType;
import com.ocean.productDict.domain.OOceanArea;
import com.ocean.productDict.service.IOOceanAreaService;
import com.ocean.common.core.controller.BaseController;
import com.ocean.common.core.domain.AjaxResult;
import com.ocean.common.utils.poi.ExcelUtil;
import com.ocean.common.core.page.TableDataInfo;

/**
 * 海区维护Controller
 *
 * @author ocean
 * @date 2023-01-03
 */
@Controller
@RequestMapping("/product/oceanArea")
public class OOceanAreaController extends BaseController
{
    private String prefix = "product/oceanArea";

    @Autowired
    private IOOceanAreaService oOceanAreaService;

    //@RequiresPermissions("product:oceanArea:view")
    @GetMapping()
    public String oceanArea()
    {
        return prefix + "/list";
    }

    /**
     * 查询海区维护列表
     */
    //@RequiresPermissions("product:oceanArea:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(OOceanArea oOceanArea)
    {
        startPage();
        List<OOceanArea> list = oOceanAreaService.selectOOceanAreaList(oOceanArea);
        return getDataTable(list);
    }

    /**
     * 导出海区维护列表
     */
    //@RequiresPermissions("product:oceanArea:export")
    @Log(title = "海区维护", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(OOceanArea oOceanArea)
    {
        List<OOceanArea> list = oOceanAreaService.selectOOceanAreaList(oOceanArea);
        ExcelUtil<OOceanArea> util = new ExcelUtil<OOceanArea>(OOceanArea.class);
        return util.exportExcel(list, "海区维护数据");
    }

    /**
     * 新增海区维护
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        Map<String,List> map = oOceanAreaService.getNameAndCodeList();
        mmap.putAll(map);
        return prefix + "/add";
    }

    /**
     * 新增保存海区维护
     */
    //@RequiresPermissions("product:oceanArea:add")
    @Log(title = "海区维护", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(OOceanArea oOceanArea)
    {
        return toAjax(oOceanAreaService.insertOOceanArea(oOceanArea));
    }

    /**
     * 修改海区维护
     */
    //@RequiresPermissions("product:oceanArea:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        Map<String,List> map = oOceanAreaService.getNameAndCodeList();
        mmap.putAll(map);
        OOceanArea oOceanArea = oOceanAreaService.selectOOceanAreaById(id);
        mmap.put("oOceanArea", oOceanArea);
        return prefix + "/edit";
    }

    /**
     * 修改保存海区维护
     */
    //@RequiresPermissions("product:oceanArea:edit")
    @Log(title = "海区维护", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(OOceanArea oOceanArea)
    {
        return toAjax(oOceanAreaService.updateOOceanArea(oOceanArea));
    }

    /**
     * 删除海区维护
     */
    //@RequiresPermissions("product:oceanArea:remove")
    @Log(title = "海区维护", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(oOceanAreaService.deleteOOceanAreaByIds(ids));
    }

    /**
     * 查看海区维护
     */
    //@RequiresPermissions("product:oceanArea:detail")
    @GetMapping("/detail/{id}")
    public String detail(@PathVariable("id") String id, ModelMap mmap)
    {
        OOceanArea oOceanArea = oOceanAreaService.selectOOceanAreaById(id);
        mmap.put("oOceanArea", oOceanArea);
        return prefix + "/detail";
    }

    /**
     * 覆盖海区弹窗
     */
    @GetMapping("oceanAreaPop")
    public String oceanAreaPop(){
        return prefix + "/oceanAreaPop";
    }
}
